<?php
session_start();
require_once 'check.php';
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>在线考试系统后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="css/global.css" media="all">
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <script src="../js/jquery-3.2.0.min.js"></script>
</head>

<body>
<div class="layui-layout layui-layout-admin" style="border-bottom: solid 5px #1aa094;">
    <div class="layui-header header header-demo">
        <div class="layui-main">
            <div class="admin-login-box">
                <a class="logo" style="left: 0;" href="#">
                    <span style="font-size: 22px;">在线考试系统</span>
                </a>
                <div class="admin-side-toggle">
                    <i class="fa fa-bars" aria-hidden="true"></i>
                </div>
                <div class="admin-side-full">
                    <i class="fa fa-life-bouy" aria-hidden="true"></i>
                </div>
            </div>
            <ul class="layui-nav admin-header-item">
                <li class="layui-nav-item">
                    <a href="javascript:;">示例一</a>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">示例二</a>
                </li>
                <li class="layui-nav-item" id="example">
                    <a href="javascript:;">示例三</a>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;" class="admin-header-user">
                        <img src="images/touxiang.jpg" />
                        <span><?php echo $_SESSION["username"] ?></span>
                    </a>
                    <dl class="layui-nav-child">
                        <dd>
                            <a href="javascript:;" id="modifypass"><i class="fa fa-user-circle" aria-hidden="true"></i> 修改密码</a>
                        </dd>
                        <dd id="lock">
                            <a href="javascript:;">
                                <i class="fa fa-lock" aria-hidden="true" style="padding-right: 3px;padding-left: 1px;"></i> 锁屏 (Alt+L)
                            </a>
                        </dd>
                        <dd>
                            <a href="#" id="logout"><i class="fa fa-sign-out" aria-hidden="true"></i> 注销</a>
                        </dd>
                    </dl>
                </li>
            </ul>
            <!--手机端显示的注销
            <ul class="layui-nav admin-header-item-mobile">
                <li class="layui-nav-item">
                    <a href="#" id="logout"><i class="fa fa-sign-out" aria-hidden="true"></i> 注销</a>
                </li>
            </ul>
            -->
        </div>
    </div>
    <div class="layui-side layui-bg-black" id="admin-side">
        <div class="layui-side-scroll" id="admin-navbar-side" lay-filter="side"></div>
    </div>
    <div class="layui-body" style="bottom: 0;border-left: solid 2px #1AA094;" id="admin-body">
        <div class="layui-tab admin-nav-card layui-tab-brief" lay-filter="admin-tab">
            <ul class="layui-tab-title">
                <li class="layui-this">
                    <i class="fa fa-dashboard" aria-hidden="true"></i>
                    <cite>系统信息</cite>
                </li>
            </ul>
            <div class="layui-tab-content" style="min-height: 150px; padding: 5px 0 0 0;">
                <div class="layui-tab-item layui-show">
                    <iframe src="info.php"></iframe>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-footer footer footer-demo" id="admin-footer">
        <div class="layui-main">
            <p>2017 &copy;
                <a href="#" target="_blank">在线考试系统后台管理</a> OnlineExam System
            </p>
        </div>
    </div>

    <!--锁屏模板 start-->
    <script type="text/template" id="lock-temp">
        <div class="admin-header-lock" id="lock-box">
            <div class="admin-header-lock-img">
                <img src="images/touxiang.jpg"/>
            </div>
            <div class="admin-header-lock-name" id="lockUserName"><?php echo $_SESSION["username"] ?></div>
            <input type="text" class="admin-header-lock-input" value="输入密码解锁.." name="lockPwd" id="lockPwd" />
            <button class="layui-btn layui-btn-small" id="unlock">解锁</button>
        </div>
    </script>
    <!--锁屏模板 end -->

    <script type="text/javascript" src="plugins/layui/layui.js"></script>
    <script type="text/javascript" src="datas/nav.js"></script>
    <script src="js/index.js"></script>
    <script>
        layui.use(['layer','form'], function() {
            var $ = layui.jquery,
                form = layui.form(),
                layer = layui.layer;
            $('#example').on('click', function () {
                layer.msg('这是一个示例');
            });
            /*
                自定义验证新密码与确认密码一致
                通过元素属性 lay-verify="pass" 进行绑定
            */
            form.verify({
                confirmpassword: function(value) {
                    if(value != $("#newpassword").val()){
                        $("#confirmpassword").val("");
                        return '确认密码与新密码不一致';
                    }
                }
            });
            var modifyBoxIndex = -1;
            $('#modifypass').on('click', function() {
                if(modifyBoxIndex != -1)
                    return;
                //通过ajax加载页面
                $.get('user/template/modifypass.html', null, function(form) {
                    modifyBoxIndex = layer.open({
                        type: 1,
                        title: '修改密码',
                        content: form,
                        btn: ['提交', '取消'],
                        shade: false,
                        offset: ['100px', '30%'],
                        area: ['600px', '320px'],
                        zIndex: 1000,
                        maxmin: true,
                        yes: function(index) {
                            $('form.layui-form').find('button[lay-filter=save]').click();
                        },
                        full: function(elem) {
                            var win = window.top === window.self ? window : parent.window;
                            $(win).on('resize', function() {
                                var $this = $(this);
                                elem.width($this.width()).height($this.height()).css({
                                    top: 0,
                                    left: 0
                                });
                                elem.children('div.layui-layer-content').height($this.height() - 95);
                            });
                        },
                        success: function(layero, index) {
                            //弹出窗口成功后渲染表单
                            var form = layui.form();
                            form.render();
                            form.on('submit(save)', function(data) {
                                $.ajax({
                                    url: 'user/user.php',
                                    type: "post",
                                    dataType: "json",
                                    data: 'method=modifypass&password='+data.field.password+'&newpassword='+data.field.newpassword,
                                    success: function (result) {
                                        layer.msg(result.msg,{time:800},function(){
                                            if (result.errorCode == 0){
                                                layer.closeAll();
                                            }else{
                                                $('form.layui-form').find('input[name=password]').focus();
                                                return false;
                                            }
                                        });
                                    },error:function () {
                                    }
                                });
                                return false;
                            });
                        },
                        end: function() {
                            modifyBoxIndex = -1;
                        }
                    });
                });
            });

            $('#logout').on('click', function(){
                $.ajax({
                    url: 'user/user.php',
                    type: "post",
                    dataType: "json",
                    data: 'method=adminLogout',
                    success: function (data) {
                        layer.msg(data.msg, {time: 800}, function () {
                            window.open("login.php","_parent");
                        });
                    }
                });
            });

        });
    </script>
</div>
</body>

</html>